package com.dom.invoapp.modular.provider;

import com.dom.api.basic.BasicStorApi;
import com.dom.api.basic.BasicSuppApi;
import com.dom.common.model.vo.basic.*;
import com.dom.invoapp.dao.entity.TStorInfo;
import com.dom.invoapp.dao.entity.TSuppInfo;
import com.dom.invoapp.dao.service.ITSuppInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 基础数据服务-供货商信息
 * @Author xllei
 * @Date 2018/11/14 下午2:51
 * @Version 1.0
 **/
@RestController
public class BasicSuppProvider extends AbstractProvider implements BasicSuppApi {
    @Autowired
    private ITSuppInfoService suppInfoService;

    @Override
    public B019A getSuppList(B019R request) {
        List<TSuppInfo> records = suppInfoService.selectInfoList(0);

        List<SuppInfo> suppInfos = new ArrayList<>();
        records.forEach(entity->{
            SuppInfo info = buildPropertites(entity);
            suppInfos.add(info);
        });

        B019A response = new B019A();
        response.setSuppInfoData(suppInfos);
        response.setTotalNum(suppInfos.size());
        return response;
    }

    private SuppInfo buildPropertites(TSuppInfo entity){
        SuppInfo suppInfo = new SuppInfo();
        BeanUtils.copyProperties(entity, suppInfo);
        return suppInfo;
    }
}
